package com.distribute.framework.model;

import com.distribute.framework.core.web.helper.Utils;
import java.lang.reflect.Field;
import java.util.Date; 
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;

import javax.annotation.Resource;

import com.distribute.framework.core.web.util.Page;
import com.distribute.framework.core.lang.*; 
import com.distribute.framework.core.web.helper.WebHelper.LzMap;
import com.distribute.framework.core.util.Function;
import com.distribute.framework.core.util.IbatisMap;
import com.distribute.framework.config.*;
import com.distribute.framework.plugin.*;

@namespace("systematic/error")
public @caption("错误信息") @database(DatabaseNames.distribute_sys) @source("distribute_sys") @table("srv_error") class SrvError implements java.io.Serializable
{
	private static final long serialVersionUID = 1l;
	private @caption("编号") @column("se_id")    @primary  @notnull  @note("  ") Long seId;// 主键 非空     
	private @caption("错误标题") @column("se_title") @like    @notnull  @note("  ") String seTitle;// 非空     
	private @caption("错误内容") @column("se_content") @like     @note("  ") String seContent;//     
	private @caption("标识") @column("se_flag")      @note("  ") String seFlag;//     
	private @caption("错误次数") @column("se_count")      @note("  ") Integer seCount;//     
	private @caption("修改时间") @column("se_update_time")     @notnull  @note("  ") Date seUpdateTime;// 非空     
	private @caption("添加时间") @column("se_add_time")     @notnull  @note("  ") Date seAddTime;// 非空     
	private @caption("状态") @column("se_status")     @notnull  @note(" 1:正常 0:无效  ") Short seStatus;// 非空 1:正常 0:无效     
	 
	//默认构造函数
	public SrvError(){ 
	
	}
	
	//主键构造函数
	public SrvError(Long id){
		this.seId = id;
	}
	
	/**所有字段构造函数 
	 SrvError(
	 	Utils.getString("seTitle")//错误标题 [非空]
	 	,Utils.getString("seContent")//错误内容
	 	,Utils.getString("seFlag")//标识
	 	,Utils.getInteger("seCount")//错误次数
	 	,Utils.getDate("seUpdateTime")//修改时间 [非空]
	 	,Utils.getDate("seAddTime")//添加时间 [非空]
	 	,Utils.getShort("seStatus")//状态 [非空]
	 )
	**/
	public SrvError(String seTitle,String seContent,String seFlag,Integer seCount,Date seUpdateTime,Date seAddTime,Short seStatus){
		this.seTitle=seTitle;
		this.seContent=seContent;
		this.seFlag=seFlag;
		this.seCount=seCount;
		this.seUpdateTime=seUpdateTime;
		this.seAddTime=seAddTime;
		this.seStatus=seStatus;
	}
	
	//设置非空字段
	public SrvError setNotNull(String seTitle,Date seUpdateTime,Date seAddTime,Short seStatus){
		this.seTitle=seTitle;
		this.seUpdateTime=seUpdateTime;
		this.seAddTime=seAddTime;
		this.seStatus=seStatus;
		return this;
	}
	/** 编号 [非空]       **/
	public SrvError seId(Long seId){
		this.seId = seId;
		this.setSeted(F.seId);
		return this;
	}
	/** 错误标题 [非空]       **/
	public SrvError seTitle(String seTitle){
		this.seTitle = seTitle;
		this.setSeted(F.seTitle);
		return this;
	}
	/** 错误内容        **/
	public SrvError seContent(String seContent){
		this.seContent = seContent;
		this.setSeted(F.seContent);
		return this;
	}
	/** 标识        **/
	public SrvError seFlag(String seFlag){
		this.seFlag = seFlag;
		this.setSeted(F.seFlag);
		return this;
	}
	/** 错误次数        **/
	public SrvError seCount(Integer seCount){
		this.seCount = seCount;
		this.setSeted(F.seCount);
		return this;
	}
	/** 修改时间 [非空]       **/
	public SrvError seUpdateTime(Date seUpdateTime){
		this.seUpdateTime = seUpdateTime;
		this.setSeted(F.seUpdateTime);
		return this;
	}
	/** 添加时间 [非空]       **/
	public SrvError seAddTime(Date seAddTime){
		this.seAddTime = seAddTime;
		this.setSeted(F.seAddTime);
		return this;
	}
	/** 状态 [非空]   1:正常 0:无效     **/
	public SrvError seStatus(Short seStatus){
		this.seStatus = seStatus;
		this.setSeted(F.seStatus);
		return this;
	}
	
	
	/**
	* 克隆对象
	**/
	public SrvError clone(){
		SrvError clone = new SrvError();
		clone.seTitle=this.seTitle;
		clone.seContent=this.seContent;
		clone.seFlag=this.seFlag;
		clone.seCount=this.seCount;
		clone.seUpdateTime=this.seUpdateTime;
		clone.seAddTime=this.seAddTime;
		clone.seStatus=this.seStatus;
		return clone;
	}
	
	
	/**
	 * 根据ID取错误信息
	 * @param id
	 * @return
	 */
	public static @api SrvError get(Long id){		
		return getSrvErrorById(id);
	}
	/**
	 * 设置ID
	 * @param id
	 * @return
	 */
	public void setId(Long id){		
		this.seId = id;
	}
	
	/**
	 * 获取所有错误信息
	 * @return
	 */
	public static @api List<SrvError> list(Map params,Integer size){
		return getSrvErrorList(params,size);
	}
	/**
	 * 获取错误信息分页
	 * @return
	 */
	public static @api Page<SrvError> page(Integer page,Integer size,Map params){
		return getSrvErrorPage(page, size , params);
	}
	
	
	/**
	 * 根据查询条件取错误信息
	 * @param params
	 * @return
	 */
	public static @api SrvError Get(Map params){
		return getSrvError(params);
	}
	/**
	 * 获取错误信息数
	 * @return
	 */
	public static @api Long count(Map params){
		return getSrvErrorCount(params);
	}
	/**
	 * 获取错误信息数
	 * @return
	 */
	public static @api <T> T eval(String eval,Map params){
		return getSrvErrorEval(eval,params);
	}
	/**
	 * 获取错误信息图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey){
		return getSrvErrorStats(params,sumKey,groupKey,-1);
	}
	/**
	 * 获取错误信息图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey,int dateType){
		return getSrvErrorStats(params,sumKey,groupKey,dateType);
	}
	
	/**
	 * 根据ID取错误信息
	 * @param id
	 * @return
	 */
	public static @api SrvError getSrvErrorById(Long id){		
		return getSrvErrorDao().getSrvErrorById(id);
	}
	/**
	 * 获取id
	 * @return
	 */
	public Long getId(){
		return this.seId;
	}
	
	
	/**
	 * 根据ID取错误信息的标识键值
	 * @param id
	 * @return
	 */
	public static @api String getKeyValue(Object key){
		Long id = Utils.parseLong(key);	
		if(id==null || id.longValue()==0 ){
			return null;
		}
		String value = null;
		if(value==null){
			SrvError srvError = get(id);
			if(srvError!=null){
				String strValue = srvError.getSeTitle$();
				if(!"SeTitle".equals("SeTitle"))
					strValue+="("+srvError.getSeTitle$()+")";
				value = strValue;
			}else{
				value = "{"+id+"}";
			}
		}
		/************LAZY3Q_ID_KEYVALUE************/
		/************LAZY3Q_ID_KEYVALUE************/
		return value;
	}	
	
	
	/**
	 * 获取当前对象的键值
	 * @return
	 */
	public String getKeyValue(){
		/************LAZY3Q_CODE_KEYVALUE************/
		/************LAZY3Q_CODE_KEYVALUE************/
		String keyValue = this.getSeTitle$();
		if(!"SeTitle".equals("SeTitle"))
			keyValue+="("+this.getSeTitle$()+")";
		return keyValue;
	}
	
	
	/**
	 * 根据关键字精确查询错误信息对象
	 * @return
	 */
	public static @api SrvError find(String key){
		if(Utils.empty(key))return null;
		Map params = new HashMap();
		if(key.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
			params.put("seId", key.toLowerCase().replaceFirst("id:", ""));					
		else{//按标识查询，精确查询
			String strDefinex = "";
			strDefinex+=" or se_title = '"+key.replaceAll("'", "''")+"'";
			strDefinex="(2=1 "+strDefinex+")";
			params.put("definex",strDefinex);
		}
		/************LAZY3Q_CODE_FIND************/
		/************LAZY3Q_CODE_FIND************/
		return SrvError.getSrvError(params);
	}
	
	
	/**
	 * 根据关键字查询错误信息
	 * @return
	 */
	public static @api List<Map> query(String key,int size,Map params,Boolean bObject){
		if(Utils.empty((String)params.get("asc")) && Utils.empty((String)params.get("desc")))//如果未传入排序字段
			params.put("desc","se_id");//那么，默认以主键降序，传给Dao层
		String strTerm=key;		
		if(!Utils.empty(strTerm)){
			if(strTerm.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
				params.put("seId", strTerm.toLowerCase().replaceFirst("id:", ""));					
			else//按标识查询，模糊查询请带%
			{
				String strDefinex = "";
				strDefinex+=" or se_title like '%"+strTerm.replaceAll("'", "''")+"%'";
				strDefinex="(2=1 "+strDefinex+")";
				params.put("definex",strDefinex);
			}
		}
		/************LAZY3Q_CODE_QUERY************/
		/************LAZY3Q_CODE_QUERY************/
			
		List<SrvError> list = page(0,size,params).getResult();
		
		/**
		* OK!取到数据拼成放入Map中，[{value,text,object:{...}},...]
		* value:数据ID，text:数据标识,object,整个对象
		**/
		List<Map> result = new java.util.ArrayList();
		for(SrvError srvError:list){
			Map map = new HashMap();
			map.put("key",srvError.getSeId().toString());
			map.put("value", Utils.js(srvError.getKeyValue()));
			if(bObject==true)
				map.put("object",srvError);
			result.add(map);
		}
		/************LAZY3Q_AFTER_QUERY************/
		/************LAZY3Q_AFTER_QUERY************/
		
		return result;
	}
	
	
	
	/**
	 * 获取所有错误信息
	 * @return
	 */
	public static @api List<SrvError> getSrvErrorList(Map params,Integer size){
		return getSrvErrorDao().getSrvErrorList(params,0,size);
	}
	
	/**
	 * 获取错误信息分页
	 * @return
	 */
	public static @api Page<SrvError> getSrvErrorPage(Integer page,Integer size,Map params){
		if(page==null)page=0;
		if(size==null)size=20;
		return getSrvErrorDao().getSrvErrorPage(page, size , params);
	}
	
	/**
	 * 根据查询条件取错误信息
	 * @param params
	 * @return
	 */
	public static @api SrvError getSrvError(Map params){
		return getSrvErrorDao().getSrvError(params);
	}
	
	/**
	 * 保存一个错误信息
	 * @param srvError
	 * @return
	 */
	public static @api SrvError saveSrvError(SrvError srvError){
		return getSrvErrorDao().saveSrvError(srvError);
	}
	
	/**
	 * 根据条件更新错误信息
	 * @param values
	 * @param params
	 */
	public static @api int updateSrvErrorByConfirm(Map values, Map params){
		return getSrvErrorDao().updateSrvErrorByConfirm(values,params);
	}
	
	/**
	 * 修改一个错误信息
	 * @param srvError
	 * @return
	 */
	public static @api int updateSrvError(SrvError srvError){
		return getSrvErrorDao().updateSrvError(srvError);
	}
	
	/**
	 * 更新错误信息非空字段
	 * @param srvError
	 */
	public static @api int updateSrvError$NotNull(SrvError srvError){
		return getSrvErrorDao().updateSrvError$NotNull(srvError);
	}
	
	/**
	 * 获取错误信息数
	 * @return
	 */
	public static @api Long getSrvErrorCount(Map params){
		return getSrvErrorDao().getSrvErrorCount(params);
	}
		
		
	/**
	 * 获取错误信息自定义求和表达式,比如求和:eval="sum(id)"
	 * @return
	 */	
	public static @api <T> T getSrvErrorEval(String eval,Map params){
		return getSrvErrorDao().getSrvErrorEval(eval,params);
	}
	/**
	 * 获取错误信息图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> getSrvErrorStats(Map params,C sumKey,C groupKey,int dateType){
		//TODO:图表统计功能未实现
		
		Map<String,Object> groups=new HashMap();//要分组的字段
		Map<String,Object> sums=new HashMap();//要统计的字段
		
		String[][] dateFormats=new String[][]{
				null,
				new String[]{"%Y","yyyy年","Y"},
				new String[]{"%Y-%m","yyyy年MM月","M"},
				new String[]{"%Y%U","yyyy年第ww周","W"},
				new String[]{"%Y-%m-%d","yyyy年MM月dd日","D"},
				new String[]{"%Y-%m-%d %H","yyyy年MM月dd日 HH点","H"},
				new String[]{"%m","MM月"},
				new String[]{"%d","dd号"},
				new String[]{"%H","HH点"} 
		};
		
		//获取要分组的字段，放入Map中
		if(dateType>0){
			groups.put(groupKey.toString(),"DATE_FORMAT({key},'"+dateFormats[dateType][0]+"')");
		}else{
			groups.put(groupKey.toString(),"{key}");
		}
		if(dateType<6 && dateType>0){ 
			params.put("asc", groupKey.toString()); 
			if(params.get(groupKey.name()+"Start")==null){
				params.put(groupKey.name()+"Start", Utils.date(new Date(), -24, dateFormats[dateType][2]));
			}
		}
		
		
		//获取要统计的字段，放入Map中
		if(sumKey.toString().equals("count")){
			sums.put(sumKey.toString(),"count(*)");
		}else{
			sums.put(sumKey.toString(),"sum({key})");
		}
		
		List<Map> list = getSrvErrorDao().getSrvErrorStats(params,groups,sums);
		
		List<Map> result = new ArrayList();
		for(Map m:list){
			Map map = new HashMap();
			Object value = m.get(sumKey.toString());
			Object name = null;
			Object groupValue = m.get(groupKey.toString());
			if(dateType>0){
				name = Utils.date(Utils.parseDate(groupValue), dateFormats[dateType][1]);
			}else{
				try{
					java.lang.reflect.Method method = SrvError.class.getMethod("get"+Utils.ForMat(groupKey.toString())+"$");
					method.setAccessible(true);
					name = method.invoke(SrvError.fromMap(m));
				}catch(Exception ex){
					ex.printStackTrace();
				}
			}
			map.put("name", name);
			map.put("value", value);
			result.add(map);
		}
		return result;
	}
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static int updateSrvError(Map set,Map where){
		if(set.isEmpty())throw new RuntimeException("set为空");
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		return getSrvErrorDao().updateSrvErrorByConfirm(set, where);
	}
	
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void deleteSrvError(Map where){
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		getSrvErrorDao().deleteSrvErrorByConfirm(where);
	}
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void delete(Long id){
		if(id==null)throw new RuntimeException("id为空");
		getSrvErrorDao().deleteSrvErrorById(id);
	}
	
	
	/**
	 * 保存错误信息对象
	 * @param params
	 * @return
	 */
	public SrvError save(){
		if(this.getSeId()!=null)
			getSrvErrorDao().updateSrvError(this);
		else
			return getSrvErrorDao().saveSrvError(this);
		return this;
	}
	
	
	/**
	 * 更新错误信息对象的非空字段,注意跟Service里面的update不一样哦
	 * @param params
	 * @return
	 */
	public int update(){
		return getSrvErrorDao().updateSrvError$NotNull(this);
	}
	
	
	/**
	 * 删除
	 * @param params
	 * @return
	 */
	public void delete(){
			getSrvErrorDao().deleteSrvErrorById(this.getSeId());
	}
	
	/**
	 * 执行事务
	 * @param function
	 */
	public static <T> T execute(Function function){
		return getSrvErrorDao().executeTransaction(function);
	}
	/*******************************编号**********************************/	
	/**
	* 编号 [非空]      
	**/
	public Long getSeId(){
		if(this.seId!=null){
			return this.seId;
		}
		return this.seId;
	}
	/**
	* 获取编号格式化(toString)
	**/
	public String getSeId$(){
		String strValue="";
		 strValue=Utils.string(this.getSeId());
	 	 return strValue;
	}
	/**
	* 根据编号反格式化
	**/
	public void setSeId$(String strValue){
		if(Utils.empty(strValue)){
			this.seId=null;
			return;
		}
	 	this.seId=Utils.parseLong(strValue);
	}
	
	/**
	* 编号 [非空]      
	**/
	public void setSeId(Long seId){
		this.seId = seId;
		this.setSeted(F.seId);
	}
	
	
	
	
	/*******************************错误标题**********************************/	
	/**
	* 错误标题 [非空]      
	**/
	public String getSeTitle(){
		if(this.seTitle!=null){
			return this.seTitle;
		}
		return this.seTitle;
	}
	/**
	* 获取错误标题格式化(toString)
	**/
	public String getSeTitle$(){
		String strValue="";
		 strValue=Utils.string(this.getSeTitle());
	 	 return strValue;
	}
	/**
	* 根据错误标题反格式化
	**/
	public void setSeTitle$(String strValue){
		if(Utils.empty(strValue)){
			this.seTitle=null;
			return;
		}
		this.seTitle=strValue;
	}
	
	/**
	* 错误标题 [非空]      
	**/
	public void setSeTitle(String seTitle){
		this.seTitle = seTitle;
		this.setSeted(F.seTitle);
	}
	
	
	
	
	/*******************************错误内容**********************************/	
	/**
	* 错误内容       
	**/
	public String getSeContent(){
		if(this.seContent!=null){
			return this.seContent;
		}
		return this.seContent;
	}
	/**
	* 获取错误内容格式化(toString)
	**/
	public String getSeContent$(){
		String strValue="";
		 strValue=Utils.string(this.getSeContent());
	 	 return strValue;
	}
	/**
	* 根据错误内容反格式化
	**/
	public void setSeContent$(String strValue){
		if(Utils.empty(strValue)){
			this.seContent=null;
			return;
		}
		this.seContent=strValue;
	}
	
	/**
	* 错误内容       
	**/
	public void setSeContent(String seContent){
		this.seContent = seContent;
		this.setSeted(F.seContent);
	}
	
	
	
	
	/*******************************标识**********************************/	
	/**
	* 标识       
	**/
	public String getSeFlag(){
		if(this.seFlag!=null){
			return this.seFlag;
		}
		return this.seFlag;
	}
	/**
	* 获取标识格式化(toString)
	**/
	public String getSeFlag$(){
		String strValue="";
		 strValue=Utils.string(this.getSeFlag());
	 	 return strValue;
	}
	/**
	* 根据标识反格式化
	**/
	public void setSeFlag$(String strValue){
		if(Utils.empty(strValue)){
			this.seFlag=null;
			return;
		}
	 	this.seFlag=strValue;
	}
	
	/**
	* 标识       
	**/
	public void setSeFlag(String seFlag){
		this.seFlag = seFlag;
		this.setSeted(F.seFlag);
	}
	
	
	
	
	/*******************************错误次数**********************************/	
	/**
	* 错误次数       
	**/
	public Integer getSeCount(){
		if(this.seCount!=null){
			return this.seCount;
		}
		return this.seCount;
	}
	/**
	* 获取错误次数格式化(toString)
	**/
	public String getSeCount$(){
		String strValue="";
		 strValue=Utils.string(this.getSeCount());
	 	 return strValue;
	}
	/**
	* 根据错误次数反格式化
	**/
	public void setSeCount$(String strValue){
		if(Utils.empty(strValue)){
			this.seCount=null;
			return;
		}
	 	this.seCount=Utils.parseInteger(strValue);
	}
	
	/**
	* 错误次数       
	**/
	public void setSeCount(Integer seCount){
		this.seCount = seCount;
		this.setSeted(F.seCount);
	}
	
	
	
	
	/*******************************修改时间**********************************/	
	/**
	* 修改时间 [非空]      
	**/
	public Date getSeUpdateTime(){
		if(this.seUpdateTime!=null){
			return this.seUpdateTime;
		}
		return this.seUpdateTime;
	}
	/**
	* 获取修改时间格式化(toString)
	**/
	public String getSeUpdateTime$(){
		String strValue="";
		 strValue=Utils.string(Utils.date(this.getSeUpdateTime(),"yyyy-MM-dd HH:mm:ss"));
	 	 return strValue;
	}
	/**
	* 根据修改时间反格式化
	**/
	public void setSeUpdateTime$(String strValue){
		if(Utils.empty(strValue)){
			this.seUpdateTime=null;
			return;
		}
	 	this.seUpdateTime=Utils.date(strValue,"yyyy-MM-dd HH:mm:ss");
	}
	
	/**
	* 修改时间 [非空]      
	**/
	public void setSeUpdateTime(Date seUpdateTime){
		this.seUpdateTime = seUpdateTime;
		this.setSeted(F.seUpdateTime);
	}
	
	
	
	
	/*******************************添加时间**********************************/	
	/**
	* 添加时间 [非空]      
	**/
	public Date getSeAddTime(){
		if(this.seAddTime!=null){
			return this.seAddTime;
		}
		return this.seAddTime;
	}
	/**
	* 获取添加时间格式化(toString)
	**/
	public String getSeAddTime$(){
		String strValue="";
		 strValue=Utils.string(Utils.date(this.getSeAddTime(),"yyyy-MM-dd HH:mm:ss"));
	 	 return strValue;
	}
	/**
	* 根据添加时间反格式化
	**/
	public void setSeAddTime$(String strValue){
		if(Utils.empty(strValue)){
			this.seAddTime=null;
			return;
		}
	 	this.seAddTime=Utils.date(strValue,"yyyy-MM-dd HH:mm:ss");
	}
	
	/**
	* 添加时间 [非空]      
	**/
	public void setSeAddTime(Date seAddTime){
		this.seAddTime = seAddTime;
		this.setSeted(F.seAddTime);
	}
	
	
	
	
	/*******************************状态**********************************/	
	/**
	* 状态 [非空]   1:正常 0:无效    
	**/
	public Short getSeStatus(){
		if(this.seStatus!=null){
			return this.seStatus;
		}
		return this.seStatus;
	}
	/**
	* 获取状态格式化(toString)
	**/
	public String getSeStatus$(){
		String strValue="";
		 if(Utils.equals(Utils.string(this.getSeStatus()),"1"))
			strValue=Utils.string("正常");		 
		 if(Utils.equals(Utils.string(this.getSeStatus()),"0"))
			strValue=Utils.string("无效");		 
	 	 return strValue;
	}
	/**
	* 根据状态反格式化
	**/
	public void setSeStatus$(String strValue){
		if(Utils.empty(strValue)){
			this.seStatus=null;
			return;
		}
		 if(Utils.equals(strValue,"正常"))
		 	this.seStatus=Utils.parseShort("1");
		 if(Utils.equals(strValue,"无效"))
		 	this.seStatus=Utils.parseShort("0");
	}
	
	/**
	* 状态 [非空]   1:正常 0:无效    
	**/
	public void setSeStatus(Short seStatus){
		this.seStatus = seStatus;
		this.setSeted(F.seStatus);
	}
	
	
	
	
	/************LAZY3Q_DEFINE_CODE************/
	/************LAZY3Q_DEFINE_CODE************/
	
	
	/**
	 * 触发器
	 */
	public static void on(Trigger.Index index,final Notify.Listener listener,Trigger.Type... types){
		Notify.on(SrvError.class, index, listener, types);
	}
	public static void on(final Notify.Listener listener,String type){
		Notify.on(SrvError.class, listener, type);
	}
	/**
	 * 当修改字段时
	 * @param filedName
	 * @param listener
	 */
	public static void on(String filedName,final Notify.Listener listener){
		Notify.on(SrvError.class, listener, filedName);
	}
	/**
	 * 当修改字段为某值时
	 * @param filedName
	 * @param value
	 * @param listener
	 */
	public static void on(String filedName,Object value,final Notify.Listener listener){
		if(value==null)return;
		Notify.on(SrvError.class, listener, filedName+"."+Utils.md5(""+value));
	}
	public void notify(String type){
		Trigger.on(SrvError.class,type, this);
	}
	
	
	/**
	 * 用来获取当有字段关联对象时的获取方式,调用如${SrvError.obj.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${SrvError.$filedName}获取关联对象
	 */
	public Map getObj(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return SrvError.class.getMethod("get$"+Utils.forMat(key.toString())).invoke(SrvError.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 用来获取某字段格式化的获取方式,调用如${SrvError.fmt.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${SrvError.filedName$}获取某字段格式化
	 */
	public Map getFmt(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return SrvError.class.getMethod("get"+Utils.ForMat(key.toString()+"$")).invoke(SrvError.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 获取查询参数链式串
	 * @return
	 */
	public static @Deprecated M where(){ return new M(0); }
	public static @Deprecated M m(){ return new M(0); }
	public static M where = new M(0,true);
	public static @database(DatabaseNames.distribute_sys) class M extends IbatisMap{
		int type = 0; 
		M linked = null;
		Boolean proxy = false;
		public M set = null;
		public M(int type){
			this.type = type;
			if(this.type==0){
				set = new M(1,true);
				set.linked = this;
			}
		};
		public M(int type,Boolean proxy){
			this.type = type;
			this.proxy=proxy;
		};
		public M proxy(){
			M m = new M(this.type);//当前的对像
			if(this.type==0){
				m.set = new M(1,true);//set对象
				m.set.linked = m;
			}else{
				m.linked=this.linked;
				this.linked.linked=m;
			}
			return m;
		}
		public @Deprecated M set(){			
			M m = this;
			m.linked=new M(1);
			m.linked.linked=m;
			return m.linked;
		};
		public M on(IbatisMap value,C column,String joinColumn){if(proxy)return proxy().on(value,column,joinColumn);this.put(value.getClass().getDeclaringClass().getSimpleName(), value);value.put("on", column.toString());value.put("to", joinColumn);return this;};
		/** 编号 [非空]       **/
		public M seId(Object seId){if(proxy)return proxy().seId(seId);  this.put("seId", seId);return this;};
	 	/** and se_id is null */
 		public M seIdNull(){if(proxy)return proxy().seIdNull();if(this.get("seIdNot")==null)this.put("seIdNot", "");this.put("seId", null);return this;};
 		/** not .... */
 		public M seIdNot(){if(proxy)return proxy().seIdNot();this.put("seIdNot", "not");return this;};
 		public M seIdNotNull(){if(proxy)return proxy().seIdNotNull();this.put("seIdNot", "not");this.put("seId", null);return this;};
 		public M seIdNot(Object seId){if(proxy)return proxy().seIdNot(seId);this.put("seIdNot", "not");this.put("seId", seId);return this;};
		/** and se_id <= ? */
		public M seIdMin(Object min){if(proxy)return proxy().seIdMin(min);this.put("seIdMin", min);return this;};
		/** and se_id >= ? */
		public M seIdMax(Object max){if(proxy)return proxy().seIdMax(max);this.put("seIdMax", max);return this;};
		public M seIdIn(String ids){
			if(proxy)return proxy().seIdIn(ids);  this.put("seIdIn", ids);return this;
		};	
		/** 错误标题 [非空]       **/
		public M seTitle(Object seTitle){if(proxy)return proxy().seTitle(seTitle);  this.put("seTitle", seTitle);return this;};
	 	/** and se_title is null */
 		public M seTitleNull(){if(proxy)return proxy().seTitleNull();if(this.get("seTitleNot")==null)this.put("seTitleNot", "");this.put("seTitle", null);return this;};
 		/** not .... */
 		public M seTitleNot(){if(proxy)return proxy().seTitleNot();this.put("seTitleNot", "not");return this;};
 		public M seTitleNotNull(){if(proxy)return proxy().seTitleNotNull();this.put("seTitleNot", "not");this.put("seTitle", null);return this;};
 		public M seTitleNot(Object seTitle){if(proxy)return proxy().seTitleNot(seTitle);this.put("seTitleNot", "not");this.put("seTitle", seTitle);return this;};
		/** 错误内容        **/
		public M seContent(Object seContent){if(proxy)return proxy().seContent(seContent);  this.put("seContent", seContent);return this;};
	 	/** and se_content is null */
 		public M seContentNull(){if(proxy)return proxy().seContentNull();if(this.get("seContentNot")==null)this.put("seContentNot", "");this.put("seContent", null);return this;};
 		/** not .... */
 		public M seContentNot(){if(proxy)return proxy().seContentNot();this.put("seContentNot", "not");return this;};
 		public M seContentNotNull(){if(proxy)return proxy().seContentNotNull();this.put("seContentNot", "not");this.put("seContent", null);return this;};
 		public M seContentNot(Object seContent){if(proxy)return proxy().seContentNot(seContent);this.put("seContentNot", "not");this.put("seContent", seContent);return this;};
		/** 标识        **/
		public M seFlag(Object seFlag){if(proxy)return proxy().seFlag(seFlag);  this.put("seFlag", seFlag);return this;};
	 	/** and se_flag is null */
 		public M seFlagNull(){if(proxy)return proxy().seFlagNull();if(this.get("seFlagNot")==null)this.put("seFlagNot", "");this.put("seFlag", null);return this;};
 		/** not .... */
 		public M seFlagNot(){if(proxy)return proxy().seFlagNot();this.put("seFlagNot", "not");return this;};
 		public M seFlagNotNull(){if(proxy)return proxy().seFlagNotNull();this.put("seFlagNot", "not");this.put("seFlag", null);return this;};
 		public M seFlagNot(Object seFlag){if(proxy)return proxy().seFlagNot(seFlag);this.put("seFlagNot", "not");this.put("seFlag", seFlag);return this;};
		/** 错误次数        **/
		public M seCount(Object seCount){if(proxy)return proxy().seCount(seCount);  this.put("seCount", seCount);return this;};
	 	/** and se_count is null */
 		public M seCountNull(){if(proxy)return proxy().seCountNull();if(this.get("seCountNot")==null)this.put("seCountNot", "");this.put("seCount", null);return this;};
 		/** not .... */
 		public M seCountNot(){if(proxy)return proxy().seCountNot();this.put("seCountNot", "not");return this;};
 		public M seCountNotNull(){if(proxy)return proxy().seCountNotNull();this.put("seCountNot", "not");this.put("seCount", null);return this;};
 		public M seCountNot(Object seCount){if(proxy)return proxy().seCountNot(seCount);this.put("seCountNot", "not");this.put("seCount", seCount);return this;};
		/** and se_count <= ? */
		public M seCountMin(Object min){if(proxy)return proxy().seCountMin(min);this.put("seCountMin", min);return this;};
		/** and se_count >= ? */
		public M seCountMax(Object max){if(proxy)return proxy().seCountMax(max);this.put("seCountMax", max);return this;};
		public M seCountIn(String ids){
			if(proxy)return proxy().seCountIn(ids);  this.put("seCountIn", ids);return this;
		};	
		/** 修改时间 [非空]       **/
		public M seUpdateTime(Object seUpdateTime){if(proxy)return proxy().seUpdateTime(seUpdateTime);  this.put("seUpdateTime", seUpdateTime);return this;};
	 	/** and se_update_time is null */
 		public M seUpdateTimeNull(){if(proxy)return proxy().seUpdateTimeNull();if(this.get("seUpdateTimeNot")==null)this.put("seUpdateTimeNot", "");this.put("seUpdateTime", null);return this;};
 		/** not .... */
 		public M seUpdateTimeNot(){if(proxy)return proxy().seUpdateTimeNot();this.put("seUpdateTimeNot", "not");return this;};
 		public M seUpdateTimeNotNull(){if(proxy)return proxy().seUpdateTimeNotNull();this.put("seUpdateTimeNot", "not");this.put("seUpdateTime", null);return this;};
 		public M seUpdateTimeNot(Object seUpdateTime){if(proxy)return proxy().seUpdateTimeNot(seUpdateTime);this.put("seUpdateTimeNot", "not");this.put("seUpdateTime", seUpdateTime);return this;};
 		/** and se_update_time >= ? */
 		public M seUpdateTimeStart(Object start){if(proxy)return proxy().seUpdateTimeStart(start);this.put("seUpdateTimeStart", start);return this;};			
 		/** and se_update_time <= ? */
 		public M seUpdateTimeEnd(Object end){if(proxy)return proxy().seUpdateTimeEnd(end);this.put("seUpdateTimeEnd", end);return this;};
		/** 添加时间 [非空]       **/
		public M seAddTime(Object seAddTime){if(proxy)return proxy().seAddTime(seAddTime);  this.put("seAddTime", seAddTime);return this;};
	 	/** and se_add_time is null */
 		public M seAddTimeNull(){if(proxy)return proxy().seAddTimeNull();if(this.get("seAddTimeNot")==null)this.put("seAddTimeNot", "");this.put("seAddTime", null);return this;};
 		/** not .... */
 		public M seAddTimeNot(){if(proxy)return proxy().seAddTimeNot();this.put("seAddTimeNot", "not");return this;};
 		public M seAddTimeNotNull(){if(proxy)return proxy().seAddTimeNotNull();this.put("seAddTimeNot", "not");this.put("seAddTime", null);return this;};
 		public M seAddTimeNot(Object seAddTime){if(proxy)return proxy().seAddTimeNot(seAddTime);this.put("seAddTimeNot", "not");this.put("seAddTime", seAddTime);return this;};
 		/** and se_add_time >= ? */
 		public M seAddTimeStart(Object start){if(proxy)return proxy().seAddTimeStart(start);this.put("seAddTimeStart", start);return this;};			
 		/** and se_add_time <= ? */
 		public M seAddTimeEnd(Object end){if(proxy)return proxy().seAddTimeEnd(end);this.put("seAddTimeEnd", end);return this;};
		/** 状态 [非空]   1:正常 0:无效     **/
		public M seStatus(Object seStatus){if(proxy)return proxy().seStatus(seStatus);  this.put("seStatus", seStatus);return this;};
	 	/** and se_status is null */
 		public M seStatusNull(){if(proxy)return proxy().seStatusNull();if(this.get("seStatusNot")==null)this.put("seStatusNot", "");this.put("seStatus", null);return this;};
 		/** not .... */
 		public M seStatusNot(){if(proxy)return proxy().seStatusNot();this.put("seStatusNot", "not");return this;};
 		public M seStatusNotNull(){if(proxy)return proxy().seStatusNotNull();this.put("seStatusNot", "not");this.put("seStatus", null);return this;};
 		public M seStatusNot(Object seStatus){if(proxy)return proxy().seStatusNot(seStatus);this.put("seStatusNot", "not");this.put("seStatus", seStatus);return this;};
		public M seStatusIn(String ids){
			if(proxy)return proxy().seStatusIn(ids);  this.put("seStatusIn", ids);return this;
		};	
	 	public M add(String key, Object value) {if(proxy)return proxy().add(key,value);this.put(key, value);return this;}
	 	public M add(F key, Object value) {if(proxy)return proxy().add(key,value);this.put(key.toString(), value);return this;}
	 	public M desc(C key) {if(proxy)return proxy().desc(key);this.put("desc", key.column);return this;}
	 	public M asc(C key) {if(proxy)return proxy().asc(key);this.put("asc", key.column);return this;}
	 	public M desc(String sql) {if(proxy)return proxy().desc(sql);this.put("desc", sql);return this;}
	 	public M asc(String sql) {if(proxy)return proxy().asc(sql);this.put("asc", sql);return this;}
	 	public M definex(String sql) {if(proxy)return proxy().definex(sql);this.put("definex", sql);return this;}
	 	/** 获取所有错误信息 **/
		public @api List<SrvError> list(Integer size){			
			return getSrvErrorList(this,size);
		}
		/** 获取错误信息分页 **/
		public @api Page<SrvError> page(Integer page,Integer size){			
			return getSrvErrorPage(page, size , this);
		}
		/** 根据查询条件取错误信息 **/
		public @api SrvError get(){			
			return getSrvError(this);
		}
		/** 获取错误信息数 **/
		public @api Long count(){			
			return getSrvErrorCount(this);
		}
		/** 获取错误信息表达式 **/
		public @api <T> T eval(String strEval){			
			return getSrvErrorEval(strEval,this);
		}
		/** 获取错误信息统计 **/
		public @api List<Map> stats(C sumKey,C groupKey,int dateType){			
			return getSrvErrorStats(this,sumKey,groupKey,dateType);
		}
		/** 获取错误信息统计 **/
		public @api List<Map> stats(C sumKey,C groupKey){			
			return getSrvErrorStats(this,sumKey,groupKey,-1);
		}
		/** 根据条件更新 **/
		public @api int update(){			
			M where = null;
			M set = null;
			if(this.type==0){
				if(this.linked==null)throw new RuntimeException("未发set");
				where = this;
				set = this.linked;
			}else{
				if(this.linked==null)throw new RuntimeException("未发where条件");
				set = this;
				where = this.linked;
			}
			return updateSrvError(set,where);
		}
		/** 根据条件删除 **/
		public @api void delete(){			
			deleteSrvError(this);
		}
	}
	
	public static class Param extends M{
		public Param(int type) {
			super(type);
		}
		public Param(int type, Boolean proxy) {
			super(type, proxy);
		}
	}
	
	/** 对象的字段描述 **/
	public static class F{
		/** 编号 [非空]       **/
		public final static @type(Long.class)  String seId="seId";
		/** 错误标题 [非空]       **/
		public final static @type(String.class) @like String seTitle="seTitle";
		/** 错误内容        **/
		public final static @type(String.class) @like String seContent="seContent";
		/** 标识        **/
		public final static @type(String.class)  String seFlag="seFlag";
		/** 错误次数        **/
		public final static @type(Integer.class)  String seCount="seCount";
		/** and se_count >= ? */
		public final static @type(Integer.class) String seCountMin="seCountMin";
		/** and se_count <= ? */
		public final static @type(Integer.class) String seCountMax="seCountMax";
		/** 修改时间 [非空]       **/
		public final static @type(Date.class)  String seUpdateTime="seUpdateTime";
	 	/** and se_update_time >= ? */
 		public final static @type(Date.class) String seUpdateTimeStart="seUpdateTimeStart";
 		/** and se_update_time <= ? */
 		public final static @type(Date.class) String seUpdateTimeEnd="seUpdateTimeEnd";
		/** 添加时间 [非空]       **/
		public final static @type(Date.class)  String seAddTime="seAddTime";
	 	/** and se_add_time >= ? */
 		public final static @type(Date.class) String seAddTimeStart="seAddTimeStart";
 		/** and se_add_time <= ? */
 		public final static @type(Date.class) String seAddTimeEnd="seAddTimeEnd";
		/** 状态 [非空]   1:正常 0:无效     **/
		public final static @type(Short.class)  String seStatus="seStatus";
	 	public static String get(String name){
			try {
				Field field = F.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	/** 对象的数据库字段描述 **/
	public static enum C{
		seId("se_id"),
		seTitle("se_title"),
		seContent("se_content"),
		seFlag("se_flag"),
		seCount("se_count"),
		seUpdateTime("se_update_time"),
		seAddTime("se_add_time"),
		seStatus("se_status"),
		count("count");
		String column;
		C(String column){
			this.column = column;
		}
		public String toString(){
			return this.column;
		}
		public static String get(String name){
			try {
				Field field = C.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	
	
	
	/**
	* 获取错误信息数据
	**/
	public static Object getData(Object param){
		if(param==null)
			return null;
		Object value = null;
		if(param.getClass()==Long.class)
			value = SrvError.get((Long)param);
		else if(param instanceof java.util.Map){
			java.util.Map params = (Map) param;
			if(params.get("size")==null)
				value = SrvError.getSrvError(params);
			else
				value = SrvError.getSrvErrorList(params, (Integer) params.get("size"));
		}else if(param.getClass()==Long.class )
			value =  SrvError.where().seId(param).get();
		else if(!Utils.empty(param.toString()))
			value = SrvError.get(Long.valueOf(param.toString()));
		return value;
	}
	
	/**对象转json**/
	public Map toJSON(){
		return toJSON(false);
	}
	public Map toJSON(boolean simple){
		Map map = new HashMap();
		map.put("id",this.getSeId());
		Utils.fms(map,simple?"id":"seId",this.getSeId(),this.getSeId$());
		Utils.fms(map,simple?"title":"seTitle",this.getSeTitle(),this.getSeTitle$());
		Utils.fms(map,simple?"content":"seContent",this.getSeContent(),this.getSeContent$());
		Utils.fms(map,simple?"flag":"seFlag",this.getSeFlag(),this.getSeFlag$());
		Utils.fms(map,simple?"count":"seCount",this.getSeCount(),this.getSeCount$());
		Utils.fms(map,simple?"updateTime":"seUpdateTime",this.getSeUpdateTime(),this.getSeUpdateTime$());
		Utils.fms(map,simple?"addTime":"seAddTime",this.getSeAddTime(),this.getSeAddTime$());
		Utils.fms(map,simple?"status":"seStatus",this.getSeStatus(),this.getSeStatus$());
		if(this.suffix!=null)map.put("suffix", this.suffix);
		/************LAZY3Q_DEFINE_TOJSON************/
		/************LAZY3Q_DEFINE_TOJSON************/
		return map;
	}
	/**对象转map**/
	public Map toMap(){
		Map map = new HashMap();
		map.put("seId",this.getSeId());
		map.put("seTitle",this.getSeTitle());
		map.put("seContent",this.getSeContent());
		map.put("seFlag",this.getSeFlag());
		map.put("seCount",this.getSeCount());
		map.put("seUpdateTime",this.getSeUpdateTime());
		map.put("seAddTime",this.getSeAddTime());
		map.put("seStatus",this.getSeStatus());
		map.put("suffix", this.suffix);
		/************LAZY3Q_DEFINE_TOMAP************/
		/************LAZY3Q_DEFINE_TOMAP************/
		return map;
	}
	/**map转对象**/
	public static SrvError fromMap(Map map){
		SrvError srvError = new SrvError();
		srvError.seId = Utils.parseLong(map.get("seId"));
		srvError.seTitle = Utils.parseString(map.get("seTitle"));
		srvError.seContent = Utils.parseString(map.get("seContent"));
		srvError.seFlag = Utils.parseString(map.get("seFlag"));
		srvError.seCount = Utils.parseInteger(map.get("seCount"));
		srvError.seUpdateTime = Utils.parseDate(map.get("seUpdateTime"));
		srvError.seAddTime = Utils.parseDate(map.get("seAddTime"));
		srvError.seStatus = Utils.parseShort(map.get("seStatus"));
		return srvError;
	}
	
	
	
	/**字段设置标记队列**/
	private Map<String,Boolean> seted=new HashMap();
	public Boolean getSeted(String key){
		return seted.get(key);
	}
	public void setSeted(String key){
		seted.put(key,true);
	}
	/**同步未set的字段**/
	public void mergeSet(SrvError old){
		Field[] fields = this.getClass().getDeclaredFields();
		try {
			for(Field field:fields){
				String key = field.getName();
				if(seted.get(key)==null && field.getAnnotation(column.class)!=null){
					field.setAccessible(true);
					field.set(this, field.get(old));					
				}
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
		
	/**自定义变量存储**/
	private Map values=new HashMap();
	public Map getValues(){
		return values;
	}
	public void setValues(String name,Object value){
		values.put(name,value);
	}
	
	/**分表时的表名后缀**/
	private String suffix;
	public String getSuffix() {
		return suffix;
	}
	public void setSuffix(String suffix) {
		this.suffix = suffix;
	}
	/**获取数据库名称**/
	public static String getDataBaseName(){
		return Utils.config("spring.datasource.distribute_sys.name");
	}
	
	public static String getIcon(){
		return "/images/icons/2008825642250778034.png";
	}
	public static String getIconfont(){
		return "icon-chexiao5";
	}
	public static enum ACT{
		列表,添加,修改,详情
	};
	public static String getUrl(ACT act,SrvError.M params){
		if(params==null)params=new SrvError.M(0);
		params.remove("joins");
		params.remove("definexs");
		params.remove("distinct");
		String strUrl = "/admin/systematic/error.edit.html?";
		if(params.get("seId")!=null){
			strUrl+="&id="+Utils.encode(""+params.get("seId"),Utils.UTF8);
		}
		if(act==ACT.列表){
			strUrl = "/admin/systematic/error.html?1=1";
		}else if(act==ACT.添加){
			strUrl+="&edittype=insert";
		}else if(act==ACT.修改){
			strUrl+="&edittype=update";
		}else if(act==ACT.详情){
			strUrl+="&edittype=detail";
		}		
		if(params!=null){
			for(Object key:params.keySet()){
				strUrl+="&"+key+"="+Utils.encode(""+params.get(key),Utils.UTF8)+"";
			}
		}
		return strUrl;
	}
	public String getDetailUrl(){
		return this.getUrl(ACT.详情, where.seId(this.getId()));
	}
	
	/**
	* 转跳到当前地址
	**/
	public static Protocol redirect(SrvError.ACT act,SrvError.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_REDIRECT");
		protocol.set("url",SrvError.getUrl(act, params));
		return protocol;
	}
	/**
	* 打开一个新的tab页面
	**/
	public static Protocol href(SrvError.ACT act,SrvError.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_HREF");
		protocol.set("url",SrvError.getUrl(act, params));
		protocol.set("title",act.name());
		return protocol;
	}
	/**
	* 显示一个消息框，并且关闭当前的对话框
	**/
	public static Protocol message(String message){
		Protocol protocol = Protocol.create(true,null,"ACT_MESSAGE");
		protocol.set("message",message);
		return protocol;
	}
	
	
	static com.distribute.framework.dao.ISrvErrorDao getSrvErrorDao(){
		return Utils.getBean("srvErrorDao");
	};
	
}